package net.libra.utils
{
	/**
	 * 
	 * @author elvisjiang
	 * @data 2012-6-21
	 */	
	public class ObjectUtil
	{
		public function ObjectUtil()
		{
		}
		static public function deepObjectToString(obj:*, level:int = 0, output:String = ""):*  
		{  
			var tabs:String = "";  
			for( var i : int = 0 ; i < level ; i++)
				tabs += "\t";
			
			
			for (var child:* in obj)  
			{  
				output += tabs + "["+ child + "] => " + obj[child];  
				
				var childOutput:String = deepObjectToString(obj[child], level + 1);  
				if (childOutput != "") output += " {\n"+ childOutput + tabs + "}";  
				
				output += "\n";  
			}  
			
			if (level > 20) return "";  
			return output;  
		}  
		/**
		 * 返回布尔值
		 */
		public static function getBoolean (value : *) : Boolean
		{
			if(value is String)
			{
				var b : Number = Number( value );
				if(b == 0 || isNaN( b ))
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			if(value is Number)
			{
				if(value == 0)
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			if(value is Boolean)
			{
				return value as Boolean;
			}
			return false;
		}
	}
}